package com.bestescortbedsystem.controller.hospitalinfo;

import com.bestescortbedsystem.entity.SesAddress;
import com.bestescortbedsystem.entity.SesHospitalinfo;
import com.bestescortbedsystem.entity.SesHospitalinfoDepartment;
import com.bestescortbedsystem.entity.SesUserIdentity;
import com.bestescortbedsystem.service.DepartmentService;
import com.bestescortbedsystem.service.HospitalininfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: HospitalinfoController
 * Package: com.bestescortbedsystem.controller.hospitalinfo
 *
 * @author: guanzepeng
 * @Date: 2021/3/1 20:38 星期一
 * @Description: 医院controller
 */
@RestController
@Slf4j
@Api(tags = "医院controller")
@RequestMapping("/hosp")
public class HospitalinfoController {

	@Resource
	private DepartmentService departmentService;

	@Resource
	private HospitalininfoService hospitalininfoService;

	/**
	 * 查询医院所对应的科室信息
	 * @param sesHospitalinfoDepartment 传入对象
	 * @param pageNum 分页
	 * @param pageSize 分页
	 * @return 返回Map
	 */
	@PostMapping("/find")
	@ApiOperation(value = "查询医院所对应的科室信息", response = Map.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum", value = "进行分页从第几条数据开始", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageSize", value = "每页显示几条数据", required = false, dataTypeClass = Integer.class)
	})
	public Map<String,Object> findBydepartment( SesHospitalinfoDepartment sesHospitalinfoDepartment,
	                                             @RequestParam(defaultValue = "1") Integer pageNum,
	                                             @RequestParam(defaultValue = "5") Integer pageSize) {
		Map<String, Object> byHospitalinfo = departmentService.findBydepartment(sesHospitalinfoDepartment, pageNum, pageSize);
		return byHospitalinfo;
	}

	/**
	 * 根据医院科室主键ID删除一条科室信息
	 * @param departmentid 传入科室ID
	 * @return 返回Boolean
	 */
	@PostMapping("/delete")
	@ApiOperation(value = "根据医院科室ID删除一条科室信息", response = Boolean.class)
	@ApiImplicitParam(name = "departmentid", value = "科室ID", required = true, dataTypeClass = Long.class)
	public Boolean deleteDepartment(Long departmentid) {
		if(departmentid == null) {
			return false;
		}
		return departmentService.deleteDepartment(departmentid);
	}

	/**
	 * 查询对接人的详细信息
	 * @param useridentityId 传入用户身份表ID
	 * @return 返回SesUserIdentity
	 */
	@PostMapping("/finduser")
	@ApiOperation(value = "查询对接人的详细信息", response = SesUserIdentity.class)
	@ApiImplicitParam(name = "useridentityId", value = "传入用户身份表ID", required = true, dataTypeClass = Long.class)
	public SesUserIdentity findByUserIdentity(Long useridentityId) {
		SesUserIdentity identity = departmentService.findByUserIdentity(useridentityId);
		return identity;
	}

	/**
	 * 根据传入的数据新增一个科室
	 * @param sesHospitalinfoDepartment 传入对象
	 * @return 返回Boolean
	 */
	@PostMapping("/insert")
	@ApiOperation(value = "根据传入的数据新增一个科室", response = Boolean.class)
	public Boolean insertDepartment(SesHospitalinfoDepartment sesHospitalinfoDepartment) {
		Boolean b = departmentService.insertDepartment(sesHospitalinfoDepartment);
		return b;
	}

	/**
	 * 带分页的医院数据展示,可以根据条件查询
	 * @param sesHospitalinfo  传入查询条件
	 * @param pageNum 从第几条数据开始
	 * @param pageSize 显示几条数据
	 * @return 返回Map
	 */
	@PostMapping("/findByHosp")
	@ApiOperation(value = "带分页的医院数据展示,可以根据条件查询", response = Map.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum", value = "进行分页从第几条数据开始", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageSize", value = "每页显示几条数据", required = false, dataTypeClass = Integer.class)
	})
	public Map<String, Object> findByHosp(SesHospitalinfo sesHospitalinfo,
	                                      @RequestParam(defaultValue = "1") Integer pageNum,
	                                      @RequestParam(defaultValue = "5") Integer pageSize
	) {
		Map<String, Object> hosp = hospitalininfoService.findByHosp(sesHospitalinfo, pageNum, pageSize);
		return hosp;
	}

	/**
	 * 省市县三级联动
	 * @param shi 输入省份ID
	 * @return 返回Map
	 */
	@PostMapping("/findcity")
	@ApiOperation(value = "省市县三级联动", response = Map.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "shi", value = "输入省份ID", required = false, defaultValue = "11", dataTypeClass = Integer.class)
	})
	public Map<String, Object> findCity(@RequestParam(defaultValue = "11") Integer shi) {
		Map<String, Object> map = new HashMap<>();

		List<SesAddress> province = hospitalininfoService.findProvince();
		map.put("sheng", province);


		List<SesAddress> city = hospitalininfoService.findCity(shi);
		map.put("shi", city);

		return map;
	}

	/**
	 * 查询县
	 * @param xian 输入城市ID
	 * @return 返回Map
	 */
	@PostMapping("/findXian")
	@ApiOperation(value = "查询县", response = Map.class)
	@ApiImplicitParam(name = "xian", value = "输入城市ID", required = false, defaultValue = "1101", dataTypeClass = Integer.class)
	public Map<String, Object> findXian(@RequestParam(defaultValue = "1101") Integer xian) {
		Map<String, Object> map = new HashMap<>();
		List<SesAddress> county = hospitalininfoService.findCounty(xian);
		map.put("xian", county);
		return map;
	}

	/**
	 * 删除医院
	 * @param hospitalinfoid 传入医院ID
	 * @return 返回Boolean
	 */
	@DeleteMapping("/deleteHosp")
	@ApiOperation(value = "删除医院", response = Boolean.class)
	@ApiImplicitParam(name = "hospitalinfoid", value = "传入医院ID", required = true, dataTypeClass = Long.class)
	public Boolean deleteHosp(Long hospitalinfoid) {
		Boolean b = hospitalininfoService.deleteHosp(hospitalinfoid);
		return b;
	}

	/**
	 * 新增医院
	 * @param sesHospitalinfo 传入医院对象
	 * @return 返回Boolean
	 */
	@PostMapping("/insertHosp")
	@ApiOperation(value = "新增医院", response = Boolean.class)
	public Boolean insertHosp(SesHospitalinfo sesHospitalinfo) {
		Boolean b = hospitalininfoService.insertHosp(sesHospitalinfo);
		return b;
	}
}
